const util = require('util')
const Ioredis = require('ioredis')
const debug = require('debug')('MDX:CACHE')

const moment = require('moment')
const {cache} = require('../config').redis
const client = new Ioredis(cache)

const HOUR = 60 * 60
const DAY = HOUR * 24
const WEEK = DAY * 7
const MONTH = DAY * 30
const YEAR = DAY * 365


/**
 * Events
 * @Todo
 */
client.on('ready', function() {})

client.on('connect', function(connection) {})

client.on("error", function(err) {})

client.on('reconnecting', function() {})

client.on('end', function() {})


/**
 * user info
 */
client.setUserInfo = async (userId,userInfo) => {
    const key = `user_${userId}`
    await client.set(key,userInfo)
    await client.expire(key,DAY*2)
}

client.getUserInfo = async (userId) => {
    await client.get(`user_${userId}`)
}

client.setTag = async (tagId, tag) => {
    const key = `tag_${tagId}`
    const xx = await client.set(key, JSON.stringify(tag))
    console.log(xx)
    await client.expire(key, DAY*2)
}

client.getTag = async (tagId) => {
    return await client.get(`tag_${tagId}`)
}



module.exports = client
